﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MapEditor.Windows.Ressources;

namespace MapEditor.Windows.DataBase
{
    public partial class BaseDeDonnees : Form
    {
        private BaseDeDonneesActions controller;

        public BaseDeDonnees()
        {
            InitializeComponent();

            controller = new BaseDeDonneesActions(this);
        }

        private void buttonAnnuler_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tabPageChipset_Enter(object sender, EventArgs e)
        {
            controller.ChargerChipsets();
        }

        private void textBoxTileset_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Chipset");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxTileset.Text = res.Selection;
                controller.currentChipset.NomFichier = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile1_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile1.Text = res.Selection;
                controller.currentChipset.AutoTile1 = res.Selection; 
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile2_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile2.Text = res.Selection;
                controller.currentChipset.AutoTile2 = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile3_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile3.Text = res.Selection;
                controller.currentChipset.AutoTile3 = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile4_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile4.Text = res.Selection;
                controller.currentChipset.AutoTile4 = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile5_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile5.Text = res.Selection;
                controller.currentChipset.AutoTile5 = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile6_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile6.Text = res.Selection;
                controller.currentChipset.AutoTile6 = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxAutotile7_Click(object sender, EventArgs e)
        {
            var res = new RessourcesSelection("Content\\Autotiles");
            var result = res.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.textBoxAutotile7.Text = res.Selection;
                controller.currentChipset.AutoTile7 = res.Selection;
                controller.RafraichirChipset();
            }
        }

        private void textBoxChipsetLabel_TextChanged(object sender, EventArgs e)
        {
            controller.currentChipset.Nom = textBoxChipsetLabel.Text;
            controller.RafraichirListChipsets();
        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            controller.EnregistrerChipsets();
        }
    }
}
